import 'package:demo/util/asset.dart';
import 'package:flutter/material.dart';
import 'total/account.dart';
import 'home/home.dart';
import 'add/add.dart';

class Tabs extends StatefulWidget {
  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  List _tabList = [
    HomePageWidget(),
    AccountPageWidget(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('烂笔头'),
        actions: <Widget>[
          new IconButton(
            icon: new Icon(Icons.add),
            onPressed: _pushAdd,
          )
        ],
      ),
      body: _tabList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index) {
          bool isTab = index == 1 ? true : false;
          SpUtil.preferences.setBool('isTab', isTab);
          setState(() {
            this._currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            // ignore: deprecated_member_use
            title: Text('首页'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.shopping_bag),
            // ignore: deprecated_member_use
            title: Text('流水'),
          ),
        ],
      ),
    );
  }

  void _pushAdd() {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) {
          return AddPage();
        },
      ),
    );
  }
}
